#include "Receive_Task.h"
uint8_t BT_Data;  // 从蓝牙收到的数据
Chassis chassis_ = {0};

void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
  if (huart->Instance == USART3) {
    uint32_t delay_time_ = xTaskGetTickCount();  // 初始化为当前时间戳
    switch (BT_Data) {
      // case 'c':
      // case 'd':
      //   chassis_.x = (BT_Data == 'd') ? Initial_Speed : -Initial_Speed;
      //   osDelayUntil(&delay_time_, 1000);
      //   chassis_.x = 0;
      //   break;
      // case 'a':
      // case 'b':
      //   chassis_.y = (BT_Data == 'a') ? Initial_Speed : -Initial_Speed;
      //   osDelayUntil(&delay_time_, 1000);
      //   chassis_.y = 0;
      //   break;
      case 'k':
      case 'm':
        chassis_.y = (BT_Data == 'k') ? Initial_Speed : -Initial_Speed;
        break;
      case 'p':
      case 'q':
        chassis_.x = (BT_Data == 'q') ? Initial_Speed : -Initial_Speed;
        break;
      // case 'g':
      // case 'h':
      //   chassis_.w = (BT_Data == 'h') ? Initial_Speed : -Initial_Speed;
      //   osDelayUntil(&delay_time_, 1000);
      //   chassis_.w = 0;
      //   break;
      default:
        chassis_.x = 0;
        chassis_.y = 0;
        break;
    }
    HAL_UART_Receive_IT(&huart3, &BT_Data, sizeof(BT_Data));
  }
}

void Start_Receive_Task(void const* argument) {
  HAL_UART_Receive_IT(&huart3, &BT_Data, sizeof(BT_Data));  // 使能串口3接收中断
  uint32_t wait_time_ = xTaskGetTickCount();                // 初始化为当前时间戳
  while (1) {
    osDelayUntil(&wait_time_, 100);
  }
}
